// 加载扩展
function loadExtend(extendss, rfun) {
    var jss = {
        category: BOTTLECMS_ROOT_PATH + "assets/category/category.js",
        category_district: BOTTLECMS_ROOT_PATH + "assets/category/category_district.js",
        geolocation: "https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js",
        dialogue: bc_asset("bc-application/Home/Assets/Home/js/bottlecms-dialogue.js?_d=243233444235"),
    }
    var num = extendss.length;
    for (var o in extendss) {
        var extend = extendss[o];
        bottlecms.getJs(jss[extend], function() {
            if (num > 1) {
                num--;
            } else {
                if (rfun) return rfun();
            }
        });
    }
}
// 定位
function getLocation(refun,reerr) {
    try{
        if (bottlecms.cookie('location')) {
            if (refun) return refun(bottlecms.cookie('location'));
        } else {
            var geolocation = new qq.maps.Geolocation(MapConfig.key, MapConfig.name);
            $(function() { //定位
                geolocation.getLocation(function(position) {
                    // window.console.log(position);
                    var positionstr = JSON.stringify(position);
                    bottlecms.cookie('location', positionstr, {
                        expires: 1440
                    });
                    if (refun) return refun(positionstr);
                    return false;
                }, function() {
                    window.console.log("getLocation:err");
                    if (reerr) return reerr();
                    return false;
                }, {
                    timeout: 5000
                });
            })
        }
    } catch (err) {
        return "";
    } 
}

loadExtend(['geolocation'], function() {
    getLocation();  
});




/*======================================
                方法
=====================================*/
var system_notice = {};
//获取通知
function getNotice() {
    bottlecms.get(BOTTLECMS_HOME_PATH + 'system_notice', null, function(data) {
        system_notice = data.obj;
    }, function() {});
}

function showNotice() {
    for (var o in system_notice) {
        $("[bottlecms-notice='" + o + "']").text(system_notice[o]);
        system_notice[o] ? $("[bottlecms-notice='" + o + "']").removeClass('hide') : $("[bottlecms-notice='" + o + "']").addClass('hide');
    }
}
getNotice()
setInterval(function() {
    getNotice();
}, 10000);
setInterval(function() {
    showNotice();
}, 1000);
// 错误记录上报
function errlog_fun(err) {
    bottlecms.log(err);
}
/*举报*/
function report_fun(target_id) {
    var afterText = '<div class="bcui-form js-pop-jubao" style="padding:0"><div class="form-item ub" style="margin-top:0"><select name="type" style="border-radius:3px"><option value="">选择举报类型</option><option value="1">虚假资料</option><option value="2">联系不上</option><option value="3">骗子</option><option value="4">其他</option></select></div><div class="form-item ub"><textarea  maxsize="150" name="content" placeholder="请填写举报原因～"></textarea></div></div>';
    bottlecms.confirm(afterText, function(modal, close) {
        var type = $(modal).find('select[name=type]').val();
        var content = $(modal).find('textarea[name=content]').val();
        bottlecms.post(BOTTLECMS_HOME_PATH + 'single/' + target_id + '/report', {
            type: type,
            content: content
        }, function(data) {
            if (data.success == true) {
                bottlecms.toast(data.msg);
                close();
            } else {
                bottlecms.toast(data.msg);
            }
        })
    })
}
/*分享*/
function share_fun() {
    $('body').append('<div class="sharepop" onClick="this.parentNode.removeChild(this)"></div>');
}
/*拉黑*/
function blacklist_fun(target_id, type, rfun) {
    var act = (type == 2) ? "unblacklist" : "blacklist";
    var text = (type == 2) ? "确定要把TA拉出黑明单吗?" : "确定要把TA拉黑吗?";
    bottlecms.confirm(text, function() {
        bottlecms.get(BOTTLECMS_HOME_PATH + 'single/' + target_id + '/' + act, null, function(data) {
            if (data.success == true) {
                bottlecms.toast(data.msg);
                if (rfun) return rfun();
            } else {
                bottlecms.toast(data.msg);
            }
        })
    });
}
/*心动*/
function like_fun(target_id, type, rfun) {
    var act = (type == 2) ? "unlike" : "like";
    bottlecms.get(BOTTLECMS_HOME_PATH + 'single/' + target_id + '/' + act, null, function(data) {
        if (data.success == true) {
            bottlecms.toast(data.msg);
            if (rfun) rfun();
        } else {
            bottlecms.toast(data.msg);
        }
    })
}
/*送礼物*/
function gift_fun(target_id, rfun) {
    // 获取礼物列表
    bottlecms.get(BOTTLECMS_HOME_PATH + 'gift', null, function(data) {
        if (data.success == true && data.list && data.list.length > 0) {
            var popupHTML = '<div class="popup gift-pupup"><a href="#" class="close-pop close-popup">关闭</a>';
            popupHTML += '<div class="gifts">';
            for (var o in data.list) {
                var v = data.list[o];

                popupHTML += '<div class="item" data-id="' + v.id + '">';
                popupHTML += '<div class="gift-cover"><img src="' + v.cover_200 + '"/></div>';
                popupHTML += '<div class="gift-name">' + v.title + '</div>';
                popupHTML += '<div class="gift-price">' + (v.price > 0 ? v.price + bc_currency("currency_2", 'name') : "免费") + '</div>';
                popupHTML += '</div>';
                // if ((parseInt(o) + 1) % 8 == 0) {
                //     popupHTML += '</li><li class="sw-slide gifts">';
                // }
            }
            popupHTML += '</div>';
            popupHTML += '</div>';
            var popup_modal = bottlecms.modal({
                content: popupHTML,
                type: 'conter'
            });
            // $(popup_modal).find(".gift-pupup-swiper").swiper({
            //     pagination: '.gift-pupup .swiper-pagination'
            // });
            // $(popup_modal.thispop).find(".gift-pupup-swiper").swipeslider({
            //     autoPlay: false,
            //     prevNextButtons: false
            // });
            // 选择购买
            $(popup_modal.thispop).find(".gifts .item[data-id]").click(function(event) {
                var gift_id = $(this).attr('data-id');
                var gift_cover = $(this).find(".gift-cover img").attr('src');
                var gift_name = $(this).find(".gift-name").html();
                popup_modal.close();
                bottlecms.confirm('确定要赠送TA此礼物吗？<div><img width="60" height="60" src="' + gift_cover + '"/><br><span style="font-size:.65rem;">' + gift_name + '</span></div>', function() {
                    bottlecms.get(BOTTLECMS_HOME_PATH + 'single/' + target_id + '/give_gift/' + gift_id, null, function(data) {
                        if (data.success == true) {
                            bottlecms.toast(data.msg);
                            if (rfun) rfun();
                        } else {
                            bottlecms.toast(data.msg);
                        }
                    })
                })
            });
        } else {
            bottlecms.toast(data.msg);
        }
    })
}
/*提示购买VIP和充值喜糖*/
function pop_tip_pay_vip_candy(msg) {
    msg = msg || "你的套餐余量不足，升级VIP套餐或充值" + bc_currency("currency_2", 'name') + "～";
    var html = '';
    html += '<div class="pop_vip_candy" style="background:#FFF; width:280px;text-align: center;border-radius: 5px;">';
    html += '<div class="content" style="padding:20px;color:#F60;">' + msg + '</div>';
    html += '<div class="btnbox"  style="padding:15px;"><a class="btn btn-sm btn-danger" href="' + BOTTLECMS_HOME_PATH + 'manage/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="' + BOTTLECMS_HOME_PATH + 'manage/account/deposit/candy">购买' + bc_currency("currency_2", 'name') + '</a></div>';
    html += '</div>';
    bottlecms.modal({
        content: html
    });
}
/*提示购买VIP*/
function pop_tip_pay_vip(msg) {
    msg = msg || "套餐余量不足，升级VIP套餐～";
    var html = '';
    html += '<div class="pop_vip_candy" style="background:#FFF; width:280px;text-align: center;border-radius: 5px;">';
    html += '<div class="content" style="padding:20px;color:#F60;">' + msg + '</div>';
    html += '<div class="btnbox"  style="padding:15px;"><a class="btn btn-sm btn-danger" href="' + BOTTLECMS_HOME_PATH + 'manage/setmeal">升级VIP</a></div>';
    html += '</div>';
    bottlecms.modal({
        content: html
    });
}
/*提示购买喜糖*/
function pop_tip_pay_candy(msg) {
    msg = msg || "" + bc_currency("currency_2", 'name') + "余额不足，充值" + bc_currency("currency_2", 'name') + "～";
    var html = '';
    html += '<div class="pop_vip_candy" style="background:#FFF; width:280px;text-align: center;border-radius: 5px;">';
    html += '<div class="content" style="padding:20px;color:#F60;">' + msg + '</div>';
    html += '<div class="btnbox"  style="padding:15px;"><a class="btn btn-sm btn-info" href="' + BOTTLECMS_HOME_PATH + 'manage/account/deposit/candy">购买' + bc_currency("currency_2", 'name') + '</a></div>';
    html += '</div>';
    bottlecms.modal({
        content: html
    });
}
/*打招呼*/
function greet_send_fun(target_id, datas, reconfirm) {
    datas['reconfirm'] = reconfirm
    bottlecms.post(BOTTLECMS_HOME_PATH + 'single/' + target_id + '/greet', datas, function(data) {
        if (data.success == true) {
            bottlecms.toast(data.msg);
        } else if (data.code == 202) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip_candy(data.msg);
        } else if (data.code == 203) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip(data.msg);
        } else if (data.code == 204) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_candy(data.msg);
        }
        // 二次确认
        else if (data.code == 201) {
            var html = '<div style="color:#666;">您不是VIP会员或套餐余量不足<br />升级VIP套餐 或使用 <font color=#F60>' + data.obj.greet_fees + '</font> ' + bc_currency("currency_2", 'name') + '支付</div>';
            html += '<div class="btnbox"  style="padding-top:19px;"><a class="btn btn-sm btn-danger" href="' + BOTTLECMS_HOME_PATH + 'manage/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="' + BOTTLECMS_HOME_PATH + 'manage/account/deposit/candy">购买' + bc_currency("currency_2", 'name') + '</a></div>';
            bottlecms.confirm(html, function() {
                return greet_send_fun(target_id, datas, true);
            }, null, {
                confirm_text: '' + bc_currency("currency_2", 'name') + '支付'
            })
        } else {
            bottlecms.toast(data.msg);
        }
    });
}
//批量打招呼
function greet_batch_fun() {
    bottlecms.get(BOTTLECMS_HOME_PATH + 'greet/matched', null, function(data) {
        if (data.success == true && data.list && data.list.length > 0) {
            var popupHTML = '';
            popupHTML += '<div class="greet_pop">';
            popupHTML += '    <div class="close close-pop" >×</div>';
            popupHTML += '    <div class="head">为你匹配</div>';
            popupHTML += '    <div class="lists">';
            for (var o in data.list) {
                var v = data.list[o];
                popupHTML += '        <div class="item active" data-id="' + v.user_id + '">';
                popupHTML += '            <div class="photo"><img src="' + v.photo_200 + '" /></div>';
                popupHTML += '            <div class="nickname ellipsis">' + v.nickname + '</div>';
                popupHTML += '            <i class="checkbox"></i>';
                popupHTML += '        </div>';
            }
            popupHTML += '    </div>';
            popupHTML += '    <div class="foot">';
            popupHTML += '        <button class="btn btn-sm js-btn">打招呼</button>';
            popupHTML += '    </div>';
            popupHTML += '</div>';
            var popup_modal = bottlecms.modal({
                content: popupHTML,
                type: 'content'
            });
            $(popup_modal.thispop).on('click', '.lists .item', function(e) {
                $(this).toggleClass('active');
            });
            $(popup_modal.thispop).on('click', '.js-btn', function() {
                var ids = [];
                $(this).parents(".greet_pop").find('.item.active').each(function(index, el) {
                    ids.push($(this).attr('data-id'));
                });
                greet_batch_send_fun(ids, {});
                popup_modal.close();
            });
        }
    })
}
//批量打招呼
function greet_batch_send_fun(target_ids, datas, reconfirm) {
    datas['reconfirm'] = reconfirm;
    datas['target_ids'] = target_ids;
    bottlecms.post(BOTTLECMS_HOME_PATH + 'greet/send', datas, function(data) {
        if (data.success == true) {
            bottlecms.toast(data.msg);
        } else if (data.code == 202) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip_candy(data.msg);
        } else if (data.code == 203) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip(data.msg);
        } else if (data.code == 204) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_candy(data.msg);
        }
        // 二次确认
        else if (data.code == 201) {
            var html = '<div style="color:#666;">您不是VIP会员或套餐余量不足<br />升级VIP套餐 或使用 <font color=#F60>' + data.obj.greet_fees + '</font> ' + bc_currency("currency_2", 'name') + '支付</div>';
            html += '<div class="btnbox"  style="padding-top:19px;"><a class="btn btn-sm btn-danger" href="' + BOTTLECMS_HOME_PATH + 'manage/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="' + BOTTLECMS_HOME_PATH + 'manage/account/deposit/candy">购买' + bc_currency("currency_2", 'name') + '</a></div>';
            bottlecms.confirm(html, function() {
                return greet_batch_send_fun(target_ids, datas, true);
            }, null, {
                confirm_text: '' + bc_currency("currency_2", 'name') + '支付'
            })
        } else {
            bottlecms.toast(data.msg);
        }
    });
}

function greet_fun(target_id) {
    // 打招呼
    bottlecms.get(BOTTLECMS_HOME_PATH + 'greet', null, function(data) {
        if (data.success == true && data.obj) {
            bottlecms.confirm('打招呼<div>' + data.obj + '</div>', function(thisobj) {
                var datas = {};
                $(thisobj).find("[name]").each(function(index, element) {
                    var name = $(this).attr("name");
                    var value = $(this).val();
                    datas[name] = value;
                    if ($(this).attr('type') == "checkbox") {
                        if ($(this).is(":checked") != true) {
                            delete datas[name];
                        }
                    }
                });
                return greet_send_fun(target_id, datas);
            })
        }
    });
}
/*修改个人资料*/
function updata_single_fun(arr, rfun) {
    if (!arr || !arr.length < 1) return;
    bottlecms.put(BOTTLECMS_HOME_PATH + "manage/singleinfo", arr, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data.obj);
            //  bottlecms.toast(data.msg);
        } else {
            bottlecms.toast(data.msg);
        }
    });
}
/*修改单身资料照片*/
function updata_single_photo_fun(photo, rfun) {
    bottlecms.put(BOTTLECMS_HOME_PATH + "manage/singlephoto", {
        photo: photo
    }, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data.obj);
            //  bottlecms.toast(data.msg);
        } else {
            bottlecms.toast(data.msg);
        }
    });
}
//照片上传
function updata_user_photo_fun(pic, rfun) {
    bottlecms.post(BOTTLECMS_HOME_PATH + "manage/photo", {
        photo: pic
    }, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data);
            bottlecms.toast(data.msg);
        } else {
            bottlecms.toast(data.msg);
        }
    });
}
//删除照片
function delete_user_photo_fun(id, rfun) {
    bottlecms.delete(BOTTLECMS_HOME_PATH + "manage/photo", {
        id: id
    }, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data);
            bottlecms.toast(data.msg);
        } else {
            bottlecms.toast(data.msg);
        }
    });
}
// 解除微信绑定
function oauth_release_fun(way, rfun) {
    bottlecms.get(BOTTLECMS_HOME_PATH + "oauth/" + way + "/release", null, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data);
            bottlecms.toast(data.msg);
        } else {
            bottlecms.toast(data.msg);
        }
    })
}
// 录音
function recorder_fun() {
    var popupHTML = '<div class="popup recorder_pop">';
    popupHTML += '<div class="titiles">最长60秒</div>';
    popupHTML += '<div class="progressbar"><div></div></div>';
    popupHTML += '<div class="btnbox"><button class="btn btn-sm btn-info js-recorder-btn">按住说话</button></div>';
    popupHTML += '<div class="rebtnbox" style="display: none;"><div class="speak"></div><button class="btn btn-sm  js-upload-btn">确认</button><button class="btn btn-sm btn-invalid js-reset-btn">重录</button></div>';
    popupHTML += '</div>';
    var popup_modal_obj = bottlecms.modal({
        content: popupHTML,
        type: 'bottom'
    });
    var popup_modal = popup_modal_obj.thispop;
    var timer;
    var time;
    var localId;
    var js_recorder_btn = $(popup_modal).find(".js-recorder-btn");
    var startRecord = function() {
        if ($(js_recorder_btn).hasClass('on')) {
            return stopRecord();
        }
        $(js_recorder_btn).addClass('on');
        wx.startRecord(); //开始录音
        clearInterval(timer);
        time = 59;
        var timei = 0;
        timer = setInterval(function() {
            if (time <= 0) {
                clearInterval(timer);
            } else {
                timei++;
                $(popup_modal).find('.progressbar div').width((timei / 60 * 100) + "%");
                $(popup_modal).find('.titiles').text('剩余' + time + '秒');
                time--;
            }
        }, 1000);
    }
    var stopRecord = function() {
        clearInterval(timer);
        if (!$(js_recorder_btn).hasClass('on')) {
            return;
        }
        $(js_recorder_btn).removeClass('on');
        if (time < 56) {
            $(popup_modal).find('.btnbox').hide();
            $(popup_modal).find('.rebtnbox').show();
        } else {
            bottlecms.toast("时间太短～")
        }
        wx.stopRecord({
            success: function(res) {
                localId = res.localId;
            },
            fail: function(res) {
                bottlecms.toast("录音失败");
                // alert("stopRecord:" + JSON.stringify(res));
            }
        });
    }
    // 开始录制
    $(js_recorder_btn).on('touchstart mousedown', function(e) {
        event.preventDefault();
        event.stopPropagation();
        // window.console.log("touchstart");
        startRecord();
    }).on('touchend touchcancel mouseup', function(e) {
        // window.console.log("touchend");
        stopRecord();
    });
    // 重录
    $(popup_modal).on('click', '.js-reset-btn', function(e) {
        $(popup_modal).find('.btnbox').show();
        $(popup_modal).find('.rebtnbox').hide();
        $(popup_modal).find('.titiles').text('最长60秒');
    });
    // 上传
    $(popup_modal).on('click', '.js-upload-btn', function(e) {
        var thisloading = bottlecms.loading("上传转码中…");
        popup_modal_obj.close();
        wx.uploadVoice({
            localId: localId, // 需要上传的音频的本地ID，由stopRecord接口获得
            isShowProgressTips: 1, // 默认为1，显示进度提示
            success: function(res) {
                var serverId = res.serverId; // 返回音频的服务器端ID
                // window.console.log(res)
                bottlecms.post(BOTTLECMS_ROOT_PATH + "wechat/loadFile", {
                    serverId: serverId
                }, function(data) {
                    thisloading.close();
                    if (data.success == true) {
                        updata_single_fun({
                            voice: data.obj
                        }, function(data) {
                            bottlecms.toast("上传成功");
                            window.location.href = window.location.href;
                        })
                    } else {
                        bottlecms.toast(data.msg);
                    }
                }, function(err) {
                    thisloading.close();
                    bottlecms.toast("转码失败！");
                })
            },
            fail: function(res) {
                thisloading.close();
                bottlecms.toast("转码失败～");
                // alert("uploadVoice:" + JSON.stringify(res));
            }
        });
    });
}
// 删除朋友
function delete_friend_fun(target_id, rfun) {
    bottlecms.confirm("确定要删除吗？", function() {
        bottlecms.delete(BOTTLECMS_HOME_PATH + "friend/" + target_id + "/delete", null, function(data) {
            if (data.success == true) {
                if (rfun) rfun(data);
                bottlecms.toast(data.msg);
            } else {
                bottlecms.toast(data.msg);
            }
        });
    })
}
// 删除聊天记录
function delete_chat_fun(target_id, rfun) {
    bottlecms.confirm("确定要删除吗？", function() {
        bottlecms.delete(BOTTLECMS_HOME_PATH + "chat/" + target_id + "/delete", null, function(data) {
            if (data.success == true) {
                if (rfun) rfun(data);
                bottlecms.toast(data.msg);
            } else {
                bottlecms.toast(data.msg);
            }
        });
    })
}
// 加好友
function apply_friend_fun(target_id, rfun, reconfirm) {
    bottlecms.get(BOTTLECMS_HOME_PATH + "friend/" + target_id + "/apply", {
        reconfirm: reconfirm
    }, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data);
            return bottlecms.toast(data.msg);
        } else if (data.code == 202) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip_candy(data.msg);
        } else if (data.code == 203) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip(data.msg);
        } else if (data.code == 204) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_candy(data.msg);
        }
        // 二次确认
        else if (data.code == 201) {
            var html = '<div style="color:#666;">您不是VIP会员或套餐余量不足<br />升级VIP套餐 或使用 <font color=#F60>' + data.obj.friend_apply_fees + '</font> ' + bc_currency("currency_2", 'name') + '支付</div>';
            html += '<div class="btnbox"  style="padding-top:19px;"><a class="btn btn-sm btn-danger" href="' + BOTTLECMS_HOME_PATH + 'manage/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="' + BOTTLECMS_HOME_PATH + 'manage/account/deposit/candy">购买' + bc_currency("currency_2", 'name') + '</a></div>';
            bottlecms.confirm(html, function() {
                return apply_friend_fun(target_id, rfun, true);
            }, null, {
                confirm_text: '' + bc_currency("currency_2", 'name') + '支付'
            })
        } else {
            return bottlecms.toast(data.msg);
        }
    });
}
// 同意加好友
function agree_apply_friend_fun(id, rfun) {
    bottlecms.get(BOTTLECMS_HOME_PATH + "friend/apply/" + id + "/agree", null, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data);
            return bottlecms.toast(data.msg);
        } else {
            return bottlecms.toast(data.msg);
        }
    });
}
// 拒绝加好友
function refuse_apply_friend_fun(id, rfun) {
    bottlecms.get(BOTTLECMS_HOME_PATH + "friend/apply/" + id + "/refuse", null, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data);
            return bottlecms.toast(data.msg);
        } else {
            return bottlecms.toast(data.msg);
        }
    });
}
// 申请查看联系方式
function apply_contact_fun(target_id, rfun, reconfirm, item) {
    bottlecms.get(BOTTLECMS_HOME_PATH + "single/" + target_id + "/apply_contact", {
        reconfirm: reconfirm
    }, function(data) {
        if (data.success == true) {
            var single = data.obj;
            var html = "";
            html += '<div class="contactbox">';
            if (item == "wechat" && (single.wechatId || single.wechat_qrcode)) {
                if (single.wechat_qrcode) html += '<div style="display:none" id="wechat_qrcode" ></div><img style="height:120px;" id="wechatqrcodeimg" />';
                if (single.wechatId) html += '<div>微信号：' + single.wechatId + '</div>';
            }
            if (item == "qq" && single.qq) {
                html += '<div>QQ：' + single.qq + '</div>';
            }
            if (item == "email" && single.email) {
                html += '<div>邮箱：' + single.email + '</div>';
            }
            if (item == "phone" && single.phone) {
                html += '<div>电话：' + single.phone + '</div>';
            }
            html += '</div>';
            // 不是好友
            bottlecms.confirm(html, null, null, {
                cancel: false,
                cancel_text: '确定'
            });
            if ($('#wechat_qrcode').length > 0) {
                $("#wechat_qrcode").qrcode({
                    render: "canvas", //table方式 
                    width: 120, //宽度 
                    height: 120, //高度 
                    text: single.wechat_qrcode //任意内容 
                });
                $('#wechatqrcodeimg').attr('src', $('#wechat_qrcode').find('canvas').get(0).toDataURL('image/jpg'))
            }
            if (rfun) rfun(data);
            return;
        } else if (data.code == 202) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip_candy(data.msg);
        } else if (data.code == 203) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_vip(data.msg);
        } else if (data.code == 204) {
            // 提示购买套餐或喜糖
            return pop_tip_pay_candy(data.msg);
        }
        // 二次确认
        else if (data.code == 201) {
            var html = '<div style="color:#666;">您不是VIP会员或套餐余量不足<br />升级VIP套餐 或使用 <font color=#F60>' + data.obj.contact_apply_fees + '</font> ' + bc_currency("currency_2", 'name') + '支付</div>';
            html += '<div class="btnbox"  style="padding-top:19px;"><a class="btn btn-sm btn-danger" href="' + BOTTLECMS_HOME_PATH + 'manage/setmeal">升级VIP</a> <a class="btn btn-sm btn-info" href="' + BOTTLECMS_HOME_PATH + 'manage/account/deposit/candy">购买' + bc_currency("currency_2", 'name') + '</a></div>';
            bottlecms.confirm(html, function() {
                return apply_contact_fun(target_id, rfun, true);
            }, null, {
                confirm_text: '' + bc_currency("currency_2", 'name') + '支付'
            })
        }
        // 不是好友
        else if (data.code == 209) {
            // 不是好友
            bottlecms.confirm('<div style="color:#F60;padding:1rem 0;">' + data.msg + '</div>', function() {
                apply_friend_fun(target_id);
            }, function() {
                bottlecms.back();
            }, {
                confirm_text: '加好友',
                cancel_text: '返回'
            });
        } else {
            return bottlecms.toast(data.msg);
        }
    });
}
// 同意查看联系方式
function agree_apply_contact_fun(id, rfun) {
    bottlecms.get(BOTTLECMS_HOME_PATH + "manage/contact/" + id + "/agree", null, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data);
            return bottlecms.toast(data.msg);
        } else {
            return bottlecms.toast(data.msg);
        }
    });
}
// 拒绝查看联系方式
function refuse_apply_contact_fun(id, rfun) {
    bottlecms.get(BOTTLECMS_HOME_PATH + "manage/contact/" + id + "/refuse", null, function(data) {
        if (data.success == true) {
            if (rfun) rfun(data);
            return bottlecms.toast(data.msg);
        } else {
            return bottlecms.toast(data.msg);
        }
    });
}
//提示上传头像
function popup_tips_photo() {
    bottlecms.modal({
        content: '<div><a href="' + BOTTLECMS_HOME_PATH + 'manage/singleinfo"><img style="display:block" width="250" height="325" src="' + bc_asset("bc-application/Mobile/Assets/Mobile/img/pop_verify_photo.png") + '" /></a></div>'
    });
}
//提示认证身份
function popup_tips_identity() {
    bottlecms.modal({
        content: '<div><a href="' + BOTTLECMS_HOME_PATH + 'manage/auth/identity"><img style="display:block" width="250" height="325" src="' + bc_asset("bc-application/Mobile/Assets/Mobile/img/pop_verify_identity.png") + '" /></a></div>'
    });
}
//提示绑定手机
function popup_tips_mobile() {
    bottlecms.modal({
        content: '<div><a href="' + BOTTLECMS_HOME_PATH + 'manage/user_mobile"><img style="display:block" width="250" height="325" src="' + bc_asset("bc-application/Mobile/Assets/Mobile/img/pop_verify_mobile.png") + '" /></a></div>'
    });
}
//提示开通VIP
function popup_tips_vip() {
    bottlecms.modal({
        content: '<div><a href="' + BOTTLECMS_HOME_PATH + 'manage/setmeal"><img style="display:block" width="250" height="325" src="' + bc_asset("bc-application/Mobile/Assets/Mobile/img/pop_verify_vip.png") + '" /></a></div>'
    });
}



$("[data-href]").click(function(e) {
    window.location.href = $(this).data("href")
});

$(document).ready(function() {
    if ($("img[lay-src]").length > 0) {
        layui.flow.lazyimg("img[lay-src]");
    }
});


// 联动
layui.form.on('select', function(data){
    var areaId=data.elem.value; 
    var o = $(this).parents('.layui-form-select').prev('select[bottlecms-mulselect]');
    if(o.length<=0){
        return;
    }
    var uuid = $(o).attr('seluuid');
    var index = parseInt($(o).attr('selindex'));
    var sel = $('select[seluuid="' + uuid + '"]');
    var table = $(o).attr('bottlecms-mulselect');

    sel.each(function() {
        var ind = parseInt($(this).attr('selindex'));
        if (ind <= index) {
            sel = sel.not($(this));
            return;
        }
        $(this).find('option').each(function(i) {
            if (i > 0) {
                $(this).remove();
            }
        });
    });
    $(o).data('lastval', areaId); 
    if(!areaId){ 
        sel.eq(0).find().eq(0).nextAll().remove();
        layui.form.render('select');
        return;
    }

    bottlecms.get(BOTTLECMS_ROOT_PATH + 'getselvt/'+table+'/' + areaId, null, function(m) {
        var m = m.list;
        if (m && m.length > 2) {
            for (var i = 0; i < m.length; i++) {
                sel.eq(0).append('<option value="' + m[i].id + '">' + m[i].name + '</option>');
            }
            layui.form.render('select');
        }
    });
});

$(document).ready(function() {
    if($(".bcui-widget-slider").length>0){
        $(".bcui-widget-slider").owlCarousel({
            loop:true,
            responsiveClass:true,
            nav:true,
            dots:false,
            navText:[
                '<i class="fa fa-angle-left"></i>',
                '<i class="fa fa-angle-right"></i>'
            ],
            margin:30,
            autoplay:false,
            autoplayTimeout:2000,
            autoplayHoverPause:true,
            smartSpeed:2000,
            center:true,
            responsive:{
                0:{items:1,}
            }
        });
    }
});
